//
//  ListCell.m
//  Dispatch
//
//  Created by hyeyeon on 14. 1. 14..
//  Copyright (c) 2014년 hyeyeon. All rights reserved.
//

#import "ListCell.h"
#import "AppDelegate.h"


#pragma mark -
#pragma mark - <<첫번째 테이블쎌>>

@implementation ListCell
@synthesize delegate;
@synthesize centerButton, leftButton, leftTitle, rightButton, rightTitle, leftBand, rightBand, leftImage, rightImage, leftNumberLabel, rightNumberLabel, leftIcon, rightIcon, winIcon;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        [self makeObject];
        if ([reuseIdentifier isEqualToString:@"IssueList_Head"]) {
            [self makeCenterButton];
            [self makeArrowButton];
            
            hotissueImages = [[NSMutableDictionary alloc] init];
            
        }
        else if([reuseIdentifier isEqualToString:@"RankingCell"]){
            [self makeNumber];
        }else if([reuseIdentifier isEqualToString:@"BattleRankingCell"]){
            [self makeNumber];
            [self makeBattleRankingObject];
        }
    }
    return self;
}


#pragma mark 생성
-(void)makeObject{
    
    leftDefaultView = [[UIImageView alloc] init];
    [self addSubview:leftDefaultView];
    
    leftButton = [[UIButton alloc] init];
    [self addSubview:leftButton];
    
    leftImage = [[UIImageView alloc] init];
    [leftButton addSubview:leftImage];
    
    leftTitle = [[UILabel alloc] init];
    [leftButton addSubview:leftTitle];
    
    leftBand = [[UIImageView alloc] init];
    [leftButton addSubview:leftBand];
    
    leftIcon = [[UIImageView alloc] init];
    [leftButton addSubview:leftIcon];
    
    rightDefaultView = [[UIImageView alloc] init];
    [self addSubview:rightDefaultView];
    
    rightButton = [[UIButton alloc] init];
    [self addSubview:rightButton];
    
    rightImage = [[UIImageView alloc] init];
    [rightButton addSubview:rightImage];
    
    rightTitle = [[UILabel alloc] init];
    [rightButton addSubview:rightTitle];
    
    rightBand = [[UIImageView alloc] init];
    [rightButton addSubview:rightBand];
    
    rightIcon = [[UIImageView alloc] init];
    [rightButton addSubview:rightIcon];
    
}

//이슈/첫번째쎌
-(void)makeArrowButton{
    
    leftArrowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 76)];
    [leftArrowButton setImage:[UIImage imageNamed:@"btn_arrow_l"] forState:UIControlStateNormal];
    [leftArrowButton setTag:1];
    [leftArrowButton setCenter:CGPointMake(leftArrowButton.frame.size.width*0.5f, 157*0.5f+20)];
    [leftArrowButton addTarget:self action:@selector(arrowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:leftArrowButton];
    
    rightArrowButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 76)];
    [rightArrowButton setImage:[UIImage imageNamed:@"btn_arrow_r"] forState:UIControlStateNormal];
    [rightArrowButton setTag:2];
    [rightArrowButton setCenter:CGPointMake(mySize.width-(rightArrowButton.frame.size.width*0.5f), leftArrowButton.center.y)];
    [rightArrowButton addTarget:self action:@selector(arrowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightArrowButton];
    
    //dot
    dotImage = [[UIImageView alloc] initWithFrame:CGRectMake(mySize.width-15-31, 15, 31, 8)];
    dotImage.image = [UIImage imageNamed:@"dot_01"];
    [self addSubview:dotImage];
    
    //top issue
    topIssue = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 31, 75)];
    [topIssue setImage:[UIImage imageNamed:@"icon_rib01"]];
    [self addSubview:topIssue];
    
}

-(void)makeCenterButton{
    centerButton = [[UIButton alloc] init];
    [self addSubview:centerButton];
    
    centerImage = [[UIImageView alloc] init];
    [centerButton addSubview:centerImage];
    
    centerTitle = [[UILabel alloc] init];
    [centerButton addSubview:centerTitle];
}

//넘버
-(void)makeNumber{
    
    leftNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 140, 50)];
    [leftButton addSubview:leftNumberLabel];
    
    rightNumberLabel = [[UILabel alloc] initWithFrame:leftNumberLabel.frame];
    [rightButton addSubview:rightNumberLabel];
    
    leftNumberLabel.font = rightNumberLabel.font = [UIFont italicSystemFontOfSize:50];
    leftNumberLabel.textColor = rightNumberLabel.textColor = ColorFromRGB(0xffffff);
    leftNumberLabel.shadowColor = rightNumberLabel.shadowColor = ColorFromRGB(0x000000);
    leftNumberLabel.textAlignment = rightNumberLabel.textAlignment = NSTextAlignmentRight;
    leftNumberLabel.backgroundColor = rightNumberLabel.backgroundColor = [UIColor clearColor];
    
    
}

//무한배틀순위에서 필요한 오브젝트
-(void)makeBattleRankingObject{
    winIcon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 31, 60)];
    winIcon.image = [UIImage imageNamed:@"icon_rib03"];
    [leftButton addSubview:winIcon];
    
    leftLoseLabel = [[NKLabel alloc] initWithFrame:CGRectMake(5, 136-25-5-10, 0, 0)];
    leftLoseLabel.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f];
    leftLoseLabel.layer.cornerRadius = 3.0f;
    [leftButton addSubview:leftLoseLabel];
    
    leftWinLabel = [[NKLabel alloc] initWithFrame:CGRectMake(5, leftLoseLabel.frame.origin.y-12, 0, 0)];
    leftWinLabel.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f];
    leftWinLabel.layer.cornerRadius = 3.0f;
    [leftButton addSubview:leftWinLabel];
    
    rightLoseLabel = [[NKLabel alloc] initWithFrame:leftLoseLabel.frame];
    rightLoseLabel.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f];
    rightLoseLabel.layer.cornerRadius = 3.0f;
    [rightButton addSubview:rightLoseLabel];
    
    rightWinLabel = [[NKLabel alloc] initWithFrame:leftWinLabel.frame];
    rightWinLabel.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f];
    rightWinLabel.layer.cornerRadius = 3.0f;
    [rightButton addSubview:rightWinLabel];
    
}

#pragma mark  이슈
//이슈에서...
-(void)cellOfIssueWithHotList:(NSArray *)hotissueList andFirstTitle:(NSString *)firstTitle andSecondTitle:(NSString *)secondTitle{
    
    
    if (hotissueList) {
        //핫이슈부분(세션1)
        
        centerImage.image = leftImage.image = rightImage.image = [UIImage imageNamed:@"thumb_600300"];
        dotImage.hidden = topIssue.hidden = NO;
        leftIcon.hidden = rightIcon.hidden = YES;
        
        
        leftArrowButton.hidden = rightArrowButton.hidden = centerButton.hidden = NO;
        leftArrowButton.enabled = rightArrowButton.enabled = YES;
        leftButton.alpha = rightButton.alpha = 0.0f;
        leftButton.enabled = rightButton.enabled = NO;
        
        //center
        [centerButton   setFrame:CGRectMake(10, 10, mySize.width-20, 150)];
        [centerImage    setFrame:CGRectMake(0, 0, centerButton.frame.size.width, centerButton.frame.size.height)];
        [centerTitle    setFrame:CGRectMake(0, centerImage.frame.size.height-30, centerImage.frame.size.width, 30)];
        centerFrame = centerButton.frame;
        
        //left
        [leftButton     setFrame:CGRectMake(centerButton.frame.origin.x-centerButton.frame.size.width,
                                            centerButton.frame.origin.y,
                                            centerButton.frame.size.width,
                                            centerButton.frame.size.height)];
        [leftImage      setFrame:CGRectMake(0, 0, leftButton.frame.size.width, leftButton.frame.size.height)];
        [leftTitle      setFrame:CGRectMake(0, leftButton.frame.size.height-30, leftButton.frame.size.width, 30)];
        leftFrame = leftButton.frame;
        
        //right
        [rightButton     setFrame:CGRectMake(centerButton.frame.origin.x+centerButton.frame.size.width,
                                            centerButton.frame.origin.y,
                                            centerButton.frame.size.width,
                                            centerButton.frame.size.height)];
        [rightImage      setFrame:CGRectMake(0, 0, rightButton.frame.size.width, rightButton.frame.size.height)];
        [rightTitle      setFrame:CGRectMake(0, rightButton.frame.size.height-30, rightButton.frame.size.width, 30)];
        rightFrame = rightButton.frame;
        
        
        leftTitle.backgroundColor = rightTitle.backgroundColor = centerTitle.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];
        leftTitle.textColor = rightTitle.textColor = centerTitle.textColor = [UIColor whiteColor];
        leftTitle.textAlignment = rightTitle.textAlignment = centerTitle.textAlignment = NSTextAlignmentCenter;
        
        if (!itemHeadArray) {
            itemHeadArray = [[NSMutableArray alloc] init];
        }
        [itemHeadArray setArray:hotissueList];
        [self wearHotissueImage];   //핫이슈 데이타 입히기
        
        [self startHotissueRolling];
        
    }else{
        //일반(세션2)
        leftArrowButton.hidden = rightArrowButton.hidden = centerButton.hidden = YES;
        leftButton.alpha = rightButton.alpha = 1.0f;
        leftButton.hidden = rightButton.hidden = NO;
        leftButton.enabled = rightButton.enabled = YES;
        dotImage.hidden = topIssue.hidden = YES;
        leftIcon.hidden = rightIcon.hidden = NO;
        
        [leftButton setFrame:CGRectMake(10, 5, 145, 136)];
        [rightButton setFrame:CGRectMake(leftButton.frame.origin.x+leftButton.frame.size.width+10,
                                         leftButton.frame.origin.y,
                                         leftButton.frame.size.width,
                                         leftButton.frame.size.height)];
        [leftImage      setFrame:CGRectMake(0, 0, leftButton.frame.size.width, leftButton.frame.size.height)];
        [rightImage     setFrame:CGRectMake(0, 0, rightButton.frame.size.width, rightButton.frame.size.height)];
        [leftTitle setFrame:CGRectMake(0, leftButton.frame.size.height-25, leftButton.frame.size.width, 25)];
        [rightTitle setFrame:CGRectMake(0, leftTitle.frame.origin.y, leftTitle.frame.size.width, leftTitle.frame.size.height)];
        leftTitle.backgroundColor = rightTitle.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];
        
        leftTitle.textColor = rightTitle.textColor = [UIColor whiteColor];
        leftTitle.text = firstTitle;
        
        leftDefaultView.frame = leftButton.frame;
        leftDefaultView.image = [UIImage imageNamed:@"thumb_290272"];
        
        rightDefaultView.frame = rightButton.frame;
        rightDefaultView.image = leftDefaultView.image;
        
        if (secondTitle) {
            rightTitle.text = secondTitle;
            rightButton.hidden = NO;
        }else{
            rightButton.hidden = YES;
        }
        
        [self stopHotissueRolling];
        leftTitle.textAlignment = rightTitle.textAlignment = NSTextAlignmentLeft;
        
    }
}

-(void)setLeftWinString:(NSString*)win andLoseString:(NSString*)lose{
    
    [leftWinLabel setText:[NSString stringWithFormat:@" WIN %@ ",win]];
    [leftWinLabel setFont:[UIFont fontWithName:@"Verdana-BoldItalic" size:7]];
    [leftWinLabel setTextColor:ColorFromRGB(0xffffff)];
    [leftWinLabel setColorWord:@"WIN" withColor:ColorFromRGB(0x55bcfd)];
    [leftWinLabel sizeToFit];
    
    [leftLoseLabel setText:[NSString stringWithFormat:@" LOSE %@ ",lose]];
    [leftLoseLabel setFont:[UIFont fontWithName:@"Verdana-BoldItalic" size:7]];
    [leftLoseLabel setTextColor:ColorFromRGB(0xffffff)];
    [leftLoseLabel setColorWord:@"LOSE" withColor:ColorFromRGB(0xd74040)];
    [leftLoseLabel sizeToFit];
}

-(void)setRightWinString:(NSString*)win andLoseString:(NSString*)lose{
    
    [rightWinLabel setText:[NSString stringWithFormat:@" WIN %@ ",win]];
    [rightWinLabel setFont:[UIFont fontWithName:@"Verdana-BoldItalic" size:7]];
    [rightWinLabel setTextColor:ColorFromRGB(0xffffff)];
    [rightWinLabel setColorWord:@"WIN" withColor:ColorFromRGB(0x55bcfd)];
    [rightWinLabel sizeToFit];
    
    [rightLoseLabel setText:[NSString stringWithFormat:@" LOSE %@ ",lose]];
    [rightLoseLabel setFont:[UIFont fontWithName:@"Verdana-BoldItalic" size:7]];
    [rightLoseLabel setTextColor:ColorFromRGB(0xffffff)];
    [rightLoseLabel setColorWord:@"LOSE" withColor:ColorFromRGB(0xd74040)];
    [rightLoseLabel sizeToFit];
}

-(void)cellLeftIconImage:(UIImage*)leftIconImage{
    if (leftIconImage) {
        leftIcon.image = leftIconImage;
        leftIcon.frame = CGRectMake(0, 0, leftIconImage.size.width*0.5f, leftIconImage.size.height*0.5f);
    }else{
        leftIcon.image = nil;
    }
}

-(void)cellRightIconImage:(UIImage*)rightIconImage{
    
    if (rightIconImage) {
        rightIcon.image = rightIconImage;
        rightIcon.frame = CGRectMake(0, 0, rightIconImage.size.width*0.5f, rightIconImage.size.height*0.5f);
    }else{
        rightIcon.image = nil;
    }
}

#pragma mark 핫이슈


-(void)loadImages{
    
}

//이미지입히기
-(void)wearHotissueImage{
    
    centerButton.enabled = YES;
    
    
    IssueView *issueView = (IssueView*)self.delegate;
    
    //가운데

    issueView.currentHeadIndex = (issueView.currentHeadIndex < 0) ? 0 : issueView.currentHeadIndex;
    issueView.currentHeadIndex = (issueView.currentHeadIndex < [itemHeadArray count]) ? issueView.currentHeadIndex : [itemHeadArray count]-1;
    centerTitle.text = [NSString stringWithFormat:@"%@ %@",[[itemHeadArray objectAtIndex:issueView.currentHeadIndex] objectForKey:@"title"],[[itemHeadArray objectAtIndex:issueView.currentHeadIndex] objectForKey:@"sub_title"]];
    NSString *fileName = [[itemHeadArray objectAtIndex:issueView.currentHeadIndex]objectForKey:@"thumb_url"];
    
    if ([hotissueImages objectForKey:fileName]) {

        NSData *imageData = (NSData*)[hotissueImages objectForKey:fileName];
        centerImage.image = [UIImage imageWithData:imageData];
        [self hotissueLeftAndRightSetting];
        dotImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"dot_%02d",issueView.currentHeadIndex+1]];
    }else{
        
        [appDelegate loadAsyncImageFromDomain:issueView.imageURL andFileName:fileName imageBlock:^(UIImage *image) {
            centerImage.image = image;
            [hotissueImages setValue:UIImageJPEGRepresentation(image, 1.0f) forKey:fileName];
            [self hotissueLeftAndRightSetting];
            dotImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"dot_%02d",issueView.currentHeadIndex+1]];
        } errorBlock:^{
            
            centerImage.image = [UIImage imageNamed:@"thumb_600300"];

            [self hotissueLeftAndRightSetting];
            dotImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"dot_%02d",issueView.currentHeadIndex+1]];
        }];
    }
    
    
    
    
}

-(void)hotissueLeftAndRightSetting{
    
    centerButton.frame = centerFrame;
    centerButton.alpha = 1.0f;
    leftButton.alpha = rightButton.alpha = 0.0f;
    leftButton.frame = leftFrame;
    rightButton.frame = rightFrame;
    
    //왼쪽(이전)
    IssueView *issueView = (IssueView*)self.delegate;
    NSInteger index = issueView.currentHeadIndex-1;
    index = (index < 0) ? [itemHeadArray count]-1 : index;
    leftTitle.text = [NSString stringWithFormat:@"%@ %@",[[itemHeadArray objectAtIndex:index] objectForKey:@"title"],[[itemHeadArray objectAtIndex:index] objectForKey:@"sub_title"]];
    NSString *imageURL = [NSString stringWithFormat:@"%@%@",issueView.imageURL, [[itemHeadArray objectAtIndex:index]objectForKey:@"thumb_url"]];
    NSString *fileName = [[itemHeadArray objectAtIndex:index]objectForKey:@"thumb_url"];
    
    if ([hotissueImages objectForKey:fileName]) {
        NSData *imageData = (NSData*)[hotissueImages objectForKey:fileName];
        leftImage.image = [UIImage imageWithData:imageData];

    }else{
        [appDelegate loadAsyncImageFromDomain:issueView.imageURL andFileName:fileName imageBlock:^(UIImage *image) {
            
            leftImage.image = image;
            [hotissueImages setValue:UIImageJPEGRepresentation(image, 1.0f) forKey:fileName];
        } errorBlock:^{
            
            leftImage.image = [UIImage imageNamed:@"thumb_600300"];
        }];
    }
    
    //오른쪽(다음)
    index = issueView.currentHeadIndex+1;
    index = (index < [itemHeadArray count]) ? index : 0;
    rightTitle.text = [NSString stringWithFormat:@"%@ %@",[[itemHeadArray objectAtIndex:index] objectForKey:@"title"],[[itemHeadArray objectAtIndex:index] objectForKey:@"sub_title"]];
    imageURL = [NSString stringWithFormat:@"%@%@",issueView.imageURL, [[itemHeadArray objectAtIndex:index]objectForKey:@"thumb_url"]];
    NSString *fileName2 = [[itemHeadArray objectAtIndex:index]objectForKey:@"thumb_url"];
    
    if ([hotissueImages objectForKey:fileName2]) {
        NSData *imageData = (NSData*)[hotissueImages objectForKey:fileName2];
        rightImage.image = [UIImage imageWithData:imageData];

    }else{
        
        [appDelegate loadAsyncImageFromDomain:issueView.imageURL andFileName:fileName2 imageBlock:^(UIImage *image) {
            
            [hotissueImages setValue:UIImageJPEGRepresentation(image, 1.0f) forKey:fileName2];
            rightImage.image = image;
        } errorBlock:^{
            
            rightImage.image = [UIImage imageNamed:@"thumb_600300"];
        }];
    }
    
    leftArrowButton.enabled = rightArrowButton.enabled = YES;
}


//애니메이션
-(void)hotissueChangeNext:(BOOL)yn{
    
    
    leftArrowButton.enabled = rightArrowButton.enabled = NO;
    IssueView *issueView = (IssueView*)self.delegate;
    [UIView animateWithDuration:1.0f animations:^{
        
        centerButton.alpha = 0.0f;
        centerButton.enabled = NO;
        
        if (yn) {
            issueView.currentHeadIndex++;
            centerButton.frame = leftFrame;
            rightButton.frame = centerFrame;
            rightButton.alpha = 1.0f;
            
        }else{
            issueView.currentHeadIndex--;
            centerButton.frame = rightFrame;
            leftButton.frame = centerFrame;
            leftButton.alpha = 1.0f;
        }
        
    } completion:^(BOOL finished) {
        
        if (issueView.currentHeadIndex < 0) {
            issueView.currentHeadIndex = [itemHeadArray count]-1;
        }
        if (issueView.currentHeadIndex >= [itemHeadArray count]) {
            issueView.currentHeadIndex = 0;
        }
        
        [self wearHotissueImage];
    }];
}

//자동전환
-(void)startHotissueRolling{
    if (!rollingTimer) {
        
        rollingTimer = [NSTimer timerWithTimeInterval:4 target:self selector:@selector(autoChaingeHotissue) userInfo:nil repeats:YES];
        
        NSRunLoop *runLoop2  = [NSRunLoop currentRunLoop];
        [runLoop2 addTimer:rollingTimer forMode:NSDefaultRunLoopMode];
    }
}

-(void)stopHotissueRolling{
    if (rollingTimer) {
        
        [rollingTimer invalidate];
        rollingTimer = nil;
    }
}

-(void)autoChaingeHotissue{
    [self hotissueChangeNext:YES];
}

//화살표
-(void)arrowButtonAction:(id)sender{
    UIButton *button = (UIButton *)sender;
    
    [self hotissueChangeNext:(button.tag == 2)];
    [self stopHotissueRolling];
    [self startHotissueRolling];
}



@end





#pragma mark - <<두번째 테이블쎌>>

@implementation SecondTypeListCell
@synthesize photoImage, dateTitle, mainTitle, subTitle;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        [self makeObject];
    }
    return self;
}

-(void)makeObject{
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 0, mySize.width-20, 1)];
    line.backgroundColor = ColorFromRGB(0xffffff);
    line.alpha = 0.1f;
    [self addSubview:line];
    
    photoImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 75, 70)];
    [self addSubview:photoImage];
    
    dateTitle = [[UILabel alloc] initWithFrame:CGRectMake(photoImage.frame.origin.x+photoImage.frame.size.width+5, photoImage.frame.origin.y, 200, 13)];
    dateTitle.backgroundColor = [UIColor clearColor];
    dateTitle.textColor = ColorFromRGB(0xa6a2a9);
    dateTitle.font = [UIFont systemFontOfSize:11];
    [self addSubview:dateTitle];
    
    mainTitle = [[UILabel alloc] initWithFrame:CGRectMake(dateTitle.frame.origin.x, dateTitle.frame.origin.y+dateTitle.frame.size.height+20, dateTitle.frame.size.width, 17)];
    mainTitle.backgroundColor = [UIColor clearColor];
    mainTitle.textColor = ColorFromRGB(0xffffff);
    mainTitle.font = [UIFont systemFontOfSize:15];
    [self addSubview:mainTitle];
    
    subTitle = [[UILabel alloc] initWithFrame:CGRectMake(mainTitle.frame.origin.x, mainTitle.frame.origin.y+mainTitle.frame.size.height+7, mainTitle.frame.size.width, mainTitle.frame.size.height)];
    subTitle.backgroundColor = [UIColor clearColor];
    subTitle.textColor = ColorFromRGB(0xffffff);
    subTitle.font = [UIFont systemFontOfSize:15];
    [self addSubview:subTitle];
}


@end


#pragma mark - <<3. MY/Follow 테이블뷰>>

@implementation FollowTableViewCell
@synthesize delegate, mStarID;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        self.backgroundColor = [UIColor clearColor];
        [self makeUnfollowCell];
        [self makeGeneral];
    }
    return self;
}

-(void)makeUnfollowCell{
    
    unfollowCellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mySize.width-40, 35)];
    unfollowCellView.backgroundColor = [UIColor clearColor];
    [self addSubview:unfollowCellView];
    
    UIButton *unfollowButton = [[UIButton alloc] initWithFrame:CGRectMake(unfollowCellView.frame.size.width-85, 0, 85, 23)];
    [unfollowButton setImage:[UIImage imageNamed:@"btn_unfollow"] forState:UIControlStateNormal];
    [unfollowButton addTarget:self.delegate action:@selector(unfollowClick:) forControlEvents:UIControlEventTouchUpInside];
    [unfollowCellView addSubview:unfollowButton];
    unfollowButton.center = CGPointMake(unfollowButton.center.x, unfollowCellView.frame.size.height*0.5f);
    
    UILabel *buttonLabel = [[UILabel alloc] initWithFrame:CGRectMake(26, 0, unfollowButton.frame.size.width-26, unfollowButton.frame.size.height)];
    buttonLabel.backgroundColor = [UIColor clearColor];
    buttonLabel.text = @"Unfollow";
    buttonLabel.textColor = ColorFromRGB(0xffffff);
    buttonLabel.font = [UIFont systemFontOfSize:14];
    [unfollowButton addSubview:buttonLabel];
    
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
    label.text = NSLocalizedString(@"checkunfollow", @"");
    label.backgroundColor = [UIColor clearColor];
    label.textColor = ColorFromRGB(0x383637);
    label.font = [UIFont systemFontOfSize:12];
    [label sizeToFit];
    label.frame = CGRectMake(0, unfollowCellView.frame.size.height-5-label.frame.size.height, label.frame.size.width, label.frame.size.height);
    [unfollowCellView addSubview:label];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, unfollowCellView.frame.size.height-1, unfollowCellView.frame.size.width, 1)];
    line.backgroundColor = ColorFromRGB(0xc2c2c2);
    [unfollowCellView addSubview:line];
}

-(void)makeGeneral{
    generalView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mySize.width-40, 35)];
    generalView.backgroundColor = [UIColor clearColor];
    [self addSubview:generalView];
    
    checkButton = [[UIButton alloc] initWithFrame:CGRectMake(generalView.frame.size.width-29, 5, 29, 35)];
    [checkButton setImage:[UIImage imageNamed:@"btn_check_off"] forState:UIControlStateNormal];
    [checkButton setImage:[UIImage imageNamed:@"btn_check_on"] forState:UIControlStateSelected];
    [checkButton addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    checkButton.center = CGPointMake(checkButton.center.x, generalView.frame.size.height*0.5f);
    [generalView addSubview:checkButton];
    
    starName = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, generalView.frame.size.width-5-29, generalView.frame.size.height)];
    starName.backgroundColor = [UIColor clearColor];
    starName.font = [UIFont systemFontOfSize:15];
    starName.textColor = ColorFromRGB(0x2a2829);
    [generalView addSubview:starName];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, generalView.frame.size.height-1, generalView.frame.size.width, 1)];
    line.backgroundColor = ColorFromRGB(0xc2c2c2);
    [generalView addSubview:line];
}

#pragma mark  체크
-(void)checkButtonAction:(id)sender{
    
    UIButton *button = (UIButton*)sender;
    button.selected = !button.selected;
    
    MyView *my = (MyView*)self.delegate;
    
    if (button.selected) {
        //언팔로우 시킬 함수에 추가
        if ([my.selectArray count] < 10) {
            
            [my.selectArray addObject:self.mStarID];
        }else{
            [appDelegate alertViewWithMessage:@"10개까지 선택할 수 있습니다." andTimeInterval:2.0f];
        }
        
    }else{
        //언팔로우 시킬 함수에서 제외
        if ([my.selectArray containsObject:self.mStarID]) {
            
            [my.selectArray removeObject:self.mStarID];
        }
    }
}

#pragma mark  샛팅
-(void)appearUnfollow{
    
    unfollowCellView.hidden = NO;
    generalView.hidden = YES;
}

-(void)appearStarName:(NSString*)name andID:(NSString *)starID andCheck:(BOOL)check{
    
    self.mStarID = starID;
    
    unfollowCellView.hidden = YES;
    generalView.hidden = NO;
    
    starName.text = name;
    checkButton.selected = check;
}

@end


#pragma mark - <<4. MY/설정 테이블뷰>>

@implementation SettingTableViewCell
@synthesize delegate, mIndex, titleLabel, checkButton, iconImage;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
        self.backgroundColor = [UIColor clearColor];
        [self makeObject];
    }
    return self;
}

-(void)makeObject{
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, mySize.width-40, 40)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont boldSystemFontOfSize:15];
    titleLabel.textColor = ColorFromRGB(0x1c1a1c);
    [self addSubview:titleLabel];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, mySize.width-40, 1)];
    line.backgroundColor = ColorFromRGB(0xc3c2c4);
    [self addSubview:line];
    
    checkButton = [[UIButton alloc] initWithFrame:CGRectMake(titleLabel.frame.size.width-53, 0, 53, 30)];
    [checkButton setImage:[UIImage imageNamed:@"btn_setting_off"] forState:UIControlStateNormal];
    [checkButton setImage:[UIImage imageNamed:@"btn_setting_on"] forState:UIControlStateSelected];
    [checkButton addTarget:self action:@selector(checkButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    checkButton.center = CGPointMake(checkButton.center.x, 20);
    [self addSubview:checkButton];
    
    removeButton = [[UIButton alloc] initWithFrame:checkButton.frame];
    [removeButton setImage:[UIImage imageNamed:@"btn_clear"] forState:UIControlStateNormal];
    [removeButton addTarget:self action:@selector(removeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:removeButton];
    
    UILabel *removeTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, removeButton.frame.size.width, removeButton.frame.size.height)];
    removeTitle.backgroundColor = [UIColor clearColor];
    removeTitle.textColor = ColorFromRGB(0xffffff);
    removeTitle.text = NSLocalizedString(@"empty", @"");
    removeTitle.font = [UIFont systemFontOfSize:13];
    removeTitle.textAlignment = NSTextAlignmentCenter;
    [removeButton addSubview:removeTitle];
    
    versionLabel = [[UIButton alloc] initWithFrame:checkButton.frame];
    [versionLabel addTarget:self action:@selector(appearCredit) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:versionLabel];
    
    UILabel *vLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, versionLabel.frame.size.width, versionLabel.frame.size.height)];
    vLabel.text = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
    vLabel.textAlignment = NSTextAlignmentCenter;
    vLabel.font = [UIFont systemFontOfSize:14];
    vLabel.textColor = ColorFromRGB(0x838387);
    [versionLabel addSubview:vLabel];
    
    iconImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    [self addSubview:iconImage];
    
}



#pragma mark  버튼
-(void)checkButtonAction:(id)sender{
    
    UIButton *button = (UIButton*)sender;
    button.selected = !button.selected;
    
    if (self.mIndex == 2) {
        //속보
        [[NSUserDefaults standardUserDefaults] setBool:button.selected forKey:UD_ALARM_NEWS];
    }else if (self.mIndex == 3) {
        //팔로우 스타속보
        [[NSUserDefaults standardUserDefaults] setBool:button.selected forKey:UD_ALARM_STAR];
    }else if (self.mIndex == 4) {
        //무한배틀1등안내
        [[NSUserDefaults standardUserDefaults] setBool:button.selected forKey:UD_ALARM_BATTLE];
    }else if (self.mIndex == 5) {
        //관심뉴스
        [[NSUserDefaults standardUserDefaults] setBool:button.selected forKey:UD_ALARM_MY];
    }
    
    MyView *my = (MyView*)self.delegate;
    [my notiYes:button.selected onType:self.mIndex];
}

-(void)removeButtonAction:(id)sender{
    [[PopupView getPopupViewWithDelegate:self] appearMessage:NSLocalizedString(@"DoYouWantToEmpty", @"") withFirstButton:NSLocalizedString(@"Ok",@"Ok") andSecondButton:NSLocalizedString(@"Cancel", @"Cancel") andTag:1];
}

-(void)appearCredit{
    if ([self.delegate respondsToSelector:@selector(appearCredit)]) {
        [self.delegate performSelector:@selector(appearCredit)];
    }
}

-(void)popupView:(PopupView *)popupView clickIndex:(NSInteger)index{
    if (popupView.tag == 1) {
        //메모리 지우겠습니까
        if (index == 0) {
            
            [appDelegate removeCacheMemory];
        }
    }
}

#pragma mark  샛팅
-(void)setString:(NSString*)string andCheckButtonHidden:(BOOL)checkHidden andremoveButtonHidden:(BOOL)removeHidden{
    
    checkButton.hidden = checkHidden;
    removeButton.hidden = removeHidden;
    titleLabel.text = string;
    versionLabel.hidden = (self.mIndex != 8);
    
    if (!checkHidden) {
        self.backgroundColor = ColorFromRGB(0xdfdde0);
        titleLabel.frame = CGRectMake(5, 0, mySize.width-40, 40);
        titleLabel.font = [UIFont systemFontOfSize:14];
        
        NSLog(@"1 title label : %@",titleLabel.text);
        
        
    }else{
        self.backgroundColor = [UIColor clearColor];
        titleLabel.frame = CGRectMake(0, 0, mySize.width-40, 40);
        titleLabel.font = [UIFont boldSystemFontOfSize:15];
        NSLog(@"2 title label : %@",titleLabel.text);
    }
    
//    if (!versionLabel.hidden) {
//        [versionLabel.titleLabel setTextColor:ColorFromRGB(0x838387)];
//    }
}

@end



#pragma mark - <<5. MY/관심이슈 테이블뷰>>
@implementation MyIssueTableViewCell
@synthesize delegate, photoImage;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self makeObject];
    }
    return self;
}

-(void)makeObject{
    
    photoImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 10, 75, 70)];
    [self addSubview:photoImage];
    
    dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(photoImage.frame.origin.x+photoImage.frame.size.width+10, 15, mySize.width-40-photoImage.frame.size.width-10, 13)];
    dateLabel.backgroundColor = [UIColor clearColor];
    dateLabel.font = [UIFont systemFontOfSize:11];
    dateLabel.textColor = ColorFromRGB(0x838387);
    [self addSubview:dateLabel];
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(dateLabel.frame.origin.x, dateLabel.frame.origin.y+dateLabel.frame.size.height+5, dateLabel.frame.size.width, 17)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:15];
    titleLabel.textColor = ColorFromRGB(0x2a2829);
    [self addSubview:titleLabel];
    
    bottomContentView = [[UIView alloc] initWithFrame:CGRectMake(dateLabel.frame.origin.x, photoImage.frame.origin.y+photoImage.frame.size.height-17, dateLabel.frame.size.width, 17)];
    [self addSubview:bottomContentView];
    
    starLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, dateLabel.frame.size.width, 17)];
    starLabel.backgroundColor = [UIColor clearColor];
    starLabel.font = [UIFont systemFontOfSize:15];
    starLabel.textColor = ColorFromRGB(0x2a2829);
    [bottomContentView addSubview:starLabel];
    
    line1 = [[UIImageView alloc] initWithFrame:CGRectZero];
    line1.image = [UIImage imageNamed:@"icon_line"];
    [bottomContentView addSubview:line1];
    
    upImage = [[UIImageView alloc] initWithFrame:CGRectZero];
    [bottomContentView addSubview:upImage];
    
    upLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    upLabel.backgroundColor = [UIColor clearColor];
    upLabel.font = [UIFont systemFontOfSize:11];
    [bottomContentView addSubview:upLabel];
    
    line2 = [[UIImageView alloc] initWithFrame:CGRectZero];
    line2.image = [UIImage imageNamed:@"icon_line"];
    [bottomContentView addSubview:line2];
    
    downImage =[[UIImageView alloc] initWithFrame:CGRectZero];
    [bottomContentView addSubview:downImage];
    
    downLabel = [[UILabel alloc] initWithFrame:CGRectZero];
    downLabel.backgroundColor = [UIColor clearColor];
    downLabel.font = [UIFont systemFontOfSize:11];
    [bottomContentView addSubview:downLabel];
    
}

-(void)setDate:(NSString*)dateString andMediaType:(NSString*)media andTitle:(NSString*)title andStar:(NSString*)star andUpClick:(BOOL)upClick andDownClick:(BOOL)downClick andUpCount:(NSString*)upCount andDownCount:(NSString*)downCount{
    
    //데이타 샛팅
    
    dateLabel.text = [NSString stringWithFormat:@"%@ %@",media, dateString];
    titleLabel.text = title;

    //스타이름 | 업 | 다운
    float centerY = starLabel.center.y;
    float originY = starLabel.frame.origin.y;
    starLabel.text = star;
    [starLabel sizeToFit];
    starLabel.center = CGPointMake(starLabel.center.x, centerY);
    
    line1.frame = CGRectMake(starLabel.frame.origin.x+starLabel.frame.size.width+8, originY, 1, 17);
    
    upImage.frame = CGRectMake(line1.frame.origin.x+line1.frame.size.width, originY, 28, 17);
    upImage.image = upClick ? [UIImage imageNamed:@"icon_up_on"] : [UIImage imageNamed:@"icon_up"];
    
    upLabel.frame = CGRectMake(upImage.frame.origin.x+upImage.frame.size.width, originY, 100, 17);   //width는 대강정함
    upLabel.text = [NSString stringWithFormat:@"%@",upCount];
    upLabel.textColor = upClick ? ColorFromRGB(0x49a1d9) : ColorFromRGB(0x838387);
    [upLabel sizeToFit];
    upLabel.center =  CGPointMake(upLabel.center.x, centerY);
    
    line2.frame = CGRectMake(upLabel.frame.origin.x+upLabel.frame.size.width+10, originY, 1, 17);
    
    downImage.frame = CGRectMake(line2.frame.origin.x+line2.frame.size.width, originY, 28, 17);
    downImage.image = downClick ? [UIImage imageNamed:@"icon_down_on"] : [UIImage imageNamed:@"icon_down"];
    
    downLabel.frame = CGRectMake(downImage.frame.origin.x+downImage.frame.size.width, originY, 100, 17);
    downLabel.text = [NSString stringWithFormat:@"%@",downCount];
    downLabel.textColor = downClick ? ColorFromRGB(0x49a1d9) : ColorFromRGB(0x838387);
    [downLabel sizeToFit];
    downLabel.center = CGPointMake(downLabel.center.x, centerY);
    
    //이름긴사람때문에 끝이 잘림.. 뒤에서부터 맞춤....
    if (downLabel.frame.origin.x+downLabel.frame.size.width > bottomContentView.frame.size.width) {
        downLabel.frame = CGRectMake(bottomContentView.frame.size.width-downLabel.frame.size.width, downLabel.frame.origin.y, downLabel.frame.size.width, downLabel.frame.size.height);
        downImage.frame = CGRectMake(downLabel.frame.origin.x-downImage.frame.size.width, downImage.frame.origin.y, downImage.frame.size.width, downImage.frame.size.height);
        line2.frame     = CGRectMake(downImage.frame.origin.x-line2.frame.size.width, line2.frame.origin.y, line2.frame.size.width, line2.frame.size.height);
        upLabel.frame   = CGRectMake(line2.frame.origin.x-upLabel.frame.size.width-10, upLabel.frame.origin.y, upLabel.frame.size.width, upLabel.frame.size.height);
        upImage.frame   = CGRectMake(upLabel.frame.origin.x-upImage.frame.size.width, upImage.frame.origin.y, upImage.frame.size.width, upImage.frame.size.height);
        line1.frame     = CGRectMake(upImage.frame.origin.x-line1.frame.size.width, line1.frame.origin.y, line1.frame.size.width, line1.frame.size.height);
        starLabel.frame = CGRectMake(0, starLabel.frame.origin.y, bottomContentView.frame.size.width-(bottomContentView.frame.size.width-line1.frame.origin.x+2), starLabel.frame.size.height);
    }
    
}

@end



#pragma mark - <<6. 배틀/배틀중인셀>>

#define offsetXIndex(index) index*photoWidth
#define frameImage(index) CGRectMake((index)*photoWidth, 0, photoWidth, mScrollView.frame.size.height)

#define IMAGE_TAG 100

@implementation BattlingTableCell

@synthesize delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        appDelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
        self.backgroundColor = [UIColor clearColor];
        firstIndex = 0;
        secondIndex = 1;
        
        [self makeScrollView];
        [self makeObject];
    }
    return self;
}

-(void)makeObject{
    
    UIImageView *icon = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 31, 60)];
    icon.image = [UIImage imageNamed:@"icon_rib02"];
    [self addSubview:icon];
    
    //선택버튼
    UIButton *clickButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, mySize.width, 161)];
    [clickButton addTarget:self action:@selector(clickButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:clickButton];
    
    
    UIButton *leftArrowButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 50, 76)];
    [leftArrowButton setImage:[UIImage imageNamed:@"btn_arrow_l"] forState:UIControlStateNormal];
    [leftArrowButton addTarget:self action:@selector(leftArrowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    leftArrowButton.center = CGPointMake(leftArrowButton.center.x, mScrollView.frame.origin.y+(mScrollView.frame.size.height*0.5f));
    [self addSubview:leftArrowButton];
    
    UIButton *rightArrowButton = [[UIButton alloc] initWithFrame:CGRectMake(mScrollView.frame.origin.x+mScrollView.frame.size.width-50, 0, 50, 76)];
    [rightArrowButton setImage:[UIImage imageNamed:@"btn_arrow_r"] forState:UIControlStateNormal];
    [rightArrowButton addTarget:self action:@selector(rightArrowButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    rightArrowButton.center = CGPointMake(rightArrowButton.center.x, mScrollView.frame.origin.y+(mScrollView.frame.size.height*0.5f));
    [self addSubview:rightArrowButton];
    
    circleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
    circleImageView.image = [UIImage imageNamed:@"vs_circle"];
    circleImageView.center = mScrollView.center;
    [self addSubview:circleImageView];
    [self animationView];   //애니메이션
    
    //무한배틀 Start!
    UIView *titleBGView = [[UIView alloc] initWithFrame:CGRectZero];
    titleBGView.backgroundColor = [UIColor colorWithWhite:0.0f alpha:0.5f];
    [self addSubview:titleBGView];
    
    if (languagesKorean) {
        
        UILabel *battleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        battleLabel.shadowColor = [UIColor blackColor];
        battleLabel.shadowOffset = CGSizeMake(1.5f,1.5f);
        battleLabel.text = @"무한 배틀,";
        battleLabel.backgroundColor = [UIColor clearColor];
        battleLabel.textColor = ColorFromRGB(0xffffff);
        battleLabel.font = [UIFont italicSystemFontOfSize:14];
        [titleBGView addSubview:battleLabel];
        [battleLabel sizeToFit];
        
        
        
        
        UILabel *startLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        startLabel.backgroundColor = [UIColor clearColor];
        startLabel.shadowColor = [UIColor blackColor];
        startLabel.shadowOffset = CGSizeMake(1.5f,1.5f);
        startLabel.text = @"START!";
        startLabel.textColor = ColorFromRGB(0xfff200);
        startLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:14];
        [titleBGView addSubview:startLabel];
        [startLabel sizeToFit];
        
        titleBGView.frame = CGRectMake(0, circleImageView.frame.origin.y+circleImageView.frame.size.height+6, battleLabel.frame.size.width+startLabel.frame.size.width+13, 20);
        titleBGView.center = CGPointMake(mScrollView.center.x, titleBGView.center.y);
        
        battleLabel.frame = CGRectMake(5, 0, battleLabel.frame.size.width, battleLabel.frame.size.height);
        startLabel.frame = CGRectMake(battleLabel.frame.origin.x+battleLabel.frame.size.width+3, 0, startLabel.frame.size.width, startLabel.frame.size.height);
        
        battleLabel.center = CGPointMake(battleLabel.center.x, titleBGView.frame.size.height*0.5f);
        startLabel.center = CGPointMake(startLabel.center.x, battleLabel.center.y);
        
        NSLog(@"rect : %@ | %@",NSStringFromCGRect(battleLabel.frame),NSStringFromCGRect(startLabel.frame));
        
//        [UIView animateWithDuration:0.5f animations:^{
//            <#code#>
//        } completion:<#^(BOOL finished)completion#>]
        
    }else{
        UILabel *startLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        startLabel.backgroundColor = [UIColor clearColor];
        startLabel.shadowColor = [UIColor blackColor];
        startLabel.shadowOffset = CGSizeMake(1.5f,1.5f);
        startLabel.text = @"START";
        startLabel.textColor = ColorFromRGB(0xfff200);
        startLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:14];
        [titleBGView addSubview:startLabel];
        [startLabel sizeToFit];
        
        
        UILabel *battleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        battleLabel.shadowColor = [UIColor blackColor];
        battleLabel.shadowOffset = CGSizeMake(1.5f,1.5f);
        battleLabel.text = @"of Star Battle!";
        battleLabel.backgroundColor = [UIColor clearColor];
        battleLabel.textColor = ColorFromRGB(0xffffff);
        battleLabel.font = [UIFont fontWithName:@"Verdana-BoldItalic" size:14];
        [titleBGView addSubview:battleLabel];
        [battleLabel sizeToFit];
        
        titleBGView.frame = CGRectMake(0, circleImageView.frame.origin.y+circleImageView.frame.size.height+6, battleLabel.frame.size.width+startLabel.frame.size.width+13, 20);
        titleBGView.center = CGPointMake(mScrollView.center.x, titleBGView.center.y);
        
        startLabel.frame = CGRectMake(5, 0, startLabel.frame.size.width, startLabel.frame.size.height);
        battleLabel.frame = CGRectMake(startLabel.frame.origin.x+startLabel.frame.size.width+3, 0, battleLabel.frame.size.width, battleLabel.frame.size.height);
        
        battleLabel.center = CGPointMake(battleLabel.center.x, titleBGView.frame.size.height*0.5f);
        startLabel.center = CGPointMake(startLabel.center.x, battleLabel.center.y);
    }
    
    
    

}

-(void)makeScrollView{
    
    mScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(10, 10, mySize.width-20, 141)];
    mScrollView.contentSize = CGSizeMake(mScrollView.frame.size.width*0.5f, mScrollView.frame.size.height);
    mScrollView.scrollEnabled = NO;
    mScrollView.delegate = self;
    mScrollView.backgroundColor = ColorFromRGB(0x4d4d57);
    [self addSubview:mScrollView];
    photoWidth = mScrollView.frame.size.width*0.5f;
    
    for (int i = -1; i<3; i++) {
        BattlingObjectView *objectView = [[BattlingObjectView alloc] initWithFrame:frameImage(i)];
        objectView.tag = i+IMAGE_TAG;
//        objectView.mLabel.text = [NSString stringWithFormat:@"%d",objectView.tag];
        [mScrollView addSubview:objectView];
    }
    
}

-(void)animationView{
    
    CGRect rect = CGRectMake(0, 0, circleImageView.frame.size.width, circleImageView.frame.size.height);
    rect = CGRectInset(rect, 2, 2);
    
    float r = rect.size.width*0.5f;
    
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(r, r*2)];
    
    for (int i = 1; i<=40; i++) {
        
        CGPoint tPoint = CGPointMake(r+(r*sinl((i/(M_PI*2)))), r+(r*cosl((i/(M_PI*2)))));
        [path addLineToPoint:tPoint];
    }
    
    pathLayer = [CAShapeLayer layer];
    pathLayer.frame = rect;
    pathLayer.geometryFlipped = YES;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = ColorFromRGB(0xfff200).CGColor;
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 4.0f;
    pathLayer.lineJoin = kCALineJoinBevel;
    
    [circleImageView.layer addSublayer:pathLayer];
    
    [self startAnimation];
    
}

-(void)startAnimation{
    
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 3.0;
    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnimation.repeatCount = 1;
    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
    
}

-(void)leftArrowButtonAction:(id)sender{
    
    float offsetX = mScrollView.contentOffset.x-photoWidth;
    if (offsetX < 0) {
        [mScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
        
    }else{
        
        [mScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
        [self changeOfImageWhenNext:NO];
    }
    
}

-(void)rightArrowButtonAction:(id)sender{
    
    float offsetX = mScrollView.contentOffset.x+photoWidth;
    
    if (offsetX > mScrollView.contentSize.width-mScrollView.frame.size.width) {
        [mScrollView setContentOffset:CGPointMake(mScrollView.contentSize.width-mScrollView.frame.size.width, 0)];
    }else{
        
        [mScrollView setContentOffset:CGPointMake(offsetX, 0) animated:YES];
        [self changeOfImageWhenNext:YES];
    }
    
}


//선택
-(void)clickButtonAction:(id)sender{
    
    if ([delegate respondsToSelector:@selector(appearBattlingView:)]) {
        [delegate performSelector:@selector(appearBattlingView:) withObject:[NSNumber numberWithInteger:firstIndex]];
    }
}


-(void)setArray:(NSArray*)list andFistIndex:(NSInteger)first andSecondIndex:(NSInteger)second{
    
    self.battlingArray  = list;
    firstIndex          = first;
    secondIndex         = second;
    
    //이미지뷰는 api나오고나서 작업
    
}

-(void)settingBattling:(NSArray *)battling{
    NSLog(@"settingBattling : %@",battling);
    
    self.battlingArray = battling;
    BattleView *battleView = (BattleView*)self.delegate;
    
    BattlingObjectView *object1 = (BattlingObjectView*)[mScrollView viewWithTag:firstIndex+IMAGE_TAG];
    BattlingObjectView *object2 = (BattlingObjectView*)[mScrollView viewWithTag:secondIndex+IMAGE_TAG];
    object1.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",firstIndex]];
    object2.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",secondIndex]];
    
    
    BattlingObjectView *objectL = (BattlingObjectView*)[mScrollView viewWithTag:(firstIndex-1)+IMAGE_TAG];
    if (objectL && firstIndex-1 >= 0) {
        objectL.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",firstIndex-1]];
    }
    
    BattlingObjectView *objectR = (BattlingObjectView*)[mScrollView viewWithTag:(secondIndex+1)+IMAGE_TAG];
    if (objectR && secondIndex+1 < [battling count]) {
        objectR.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",secondIndex+1]];
    }
    
    [mScrollView setContentSize:CGSizeMake((mScrollView.frame.size.width*0.5)*battling.count, mScrollView.frame.size.height)];
    
    
}


#pragma mark 입히기

-(void)wearFirstIndex:(NSInteger)fIndex andSecondIndex:(NSInteger)sIndex{
    BattleView *battleView = (BattleView*)self.delegate;
    
    firstImageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",fIndex]];
    secondImageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",sIndex]];
    
}

-(void)changeOfImageWhenNext:(BOOL)next{
    
    BattleView *battleView = (BattleView*)self.delegate;
    
    BattlingObjectView *objectL = (BattlingObjectView*)[mScrollView viewWithTag:(firstIndex-1)+IMAGE_TAG];
    BattlingObjectView *objectR = (BattlingObjectView*)[mScrollView viewWithTag:(secondIndex+1)+IMAGE_TAG];
    

    if (next) {
        
        firstIndex = (firstIndex+1 < [self.battlingArray count]-1) ? firstIndex+1 : [self.battlingArray count]-2;
        secondIndex = firstIndex+1;
        
        objectL.frame = frameImage(secondIndex+1);
        objectL.tag = (secondIndex+1)+IMAGE_TAG;
        objectL.mLabel.text = [NSString stringWithFormat:@"%d",(secondIndex+1)+IMAGE_TAG];
        if (secondIndex+1 < [self.battlingArray count]) {
            objectL.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",secondIndex+1]];
        }
    }else{
        firstIndex = (firstIndex-1 < 0) ? 0 : firstIndex-1;
        secondIndex = firstIndex+1;
        
        objectR.frame = frameImage(firstIndex-1);
        objectR.tag = (firstIndex-1)+IMAGE_TAG;
        objectR.mLabel.text = [NSString stringWithFormat:@"%d",(firstIndex-1)+IMAGE_TAG];
        if (firstIndex-1 < [self.battlingArray count]) {
            
            objectL.imageView.image = [battleView.battlingImages objectForKey:[NSString stringWithFormat:@"image_%d",secondIndex-1]];
        }
    }
}

#pragma mark scrollView Delegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    
    
}

@end


#pragma mark - <<7. 배틀/지난순위셀>>

@implementation BattleRankingTableCell
@synthesize firstImage, secondImage, thirdImage, dateLabel;
@synthesize delegate;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.backgroundColor = [UIColor clearColor];
        [self makeObject];
    }
    return self;
}

-(void)makeObject{
    
    UIView *topBGView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, mySize.width-20, 20)];
    topBGView.backgroundColor = ColorFromRGB(0x211f20);
    [self addSubview:topBGView];
    
    UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 21, 20)];
    icon.image = [UIImage imageNamed:@"icon_calendar"];
    [topBGView addSubview:icon];
    
    dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(icon.frame.origin.x+icon.frame.size.width, 0, topBGView.frame.size.width, topBGView.frame.size.height)];
    dateLabel.backgroundColor = [UIColor clearColor];
    dateLabel.textColor = ColorFromRGB(0xffffff);
    dateLabel.font = [UIFont systemFontOfSize:10];
    [topBGView addSubview:dateLabel];
    
    //defulat
    UIView *defultBGView = [[UIView alloc] initWithFrame:CGRectMake(10, topBGView.frame.origin.y+topBGView.frame.size.height, topBGView.frame.size.width, 94)];
    defultBGView.backgroundColor = ColorFromRGB(0x4d4d57);
    [self addSubview:defultBGView];
    
    for (int i = 0; i<3; i++) {
        UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"thumb_default"]];
        image.frame = CGRectMake(0, 0, 63, 59);
        image.center = CGPointMake(50+(100*i), defultBGView.frame.size.height*0.5f);
        [defultBGView addSubview:image];
    }
    
    
    firstImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, topBGView.frame.origin.y+topBGView.frame.size.height, 100, 94)];
    firstImage.backgroundColor = [UIColor clearColor];
    [self addSubview:firstImage];
    
    secondImage = [[UIImageView alloc] initWithFrame:CGRectMake(firstImage.frame.origin.x+firstImage.frame.size.width, firstImage.frame.origin.y, firstImage.frame.size.width, firstImage.frame.size.height)];
    secondImage.backgroundColor = firstImage.backgroundColor;
    [self addSubview:secondImage];
    
    thirdImage = [[UIImageView alloc] initWithFrame:CGRectMake(secondImage.frame.origin.x+secondImage.frame.size.width, firstImage.frame.origin.y, firstImage.frame.size.width, firstImage.frame.size.height)];
    thirdImage.backgroundColor = firstImage.backgroundColor;
    [self addSubview:thirdImage];
    
    UILabel *number1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
    number1.text = @"1";
    number1.font = [UIFont italicSystemFontOfSize:25];
    number1.textColor = ColorFromRGB(0xffffff);
    number1.textAlignment = NSTextAlignmentRight;
    number1.shadowColor = ColorFromRGB(0x000000);
    number1.backgroundColor = [UIColor clearColor];
    [firstImage addSubview:number1];
    
    UILabel *number2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
    number2.text = @"2";
    number2.font = [UIFont italicSystemFontOfSize:25];
    number2.textColor = ColorFromRGB(0xffffff);
    number2.textAlignment = NSTextAlignmentRight;
    number2.shadowColor = ColorFromRGB(0x000000);
    number2.backgroundColor = [UIColor clearColor];
    [secondImage addSubview:number2];
    
    UILabel *number3 = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 95, 30)];
    number3.text = @"3";
    number3.font = [UIFont italicSystemFontOfSize:25];
    number3.textColor = ColorFromRGB(0xffffff);
    number3.textAlignment = NSTextAlignmentRight;
    number3.shadowColor = ColorFromRGB(0x000000);
    number3.backgroundColor = [UIColor clearColor];
    [thirdImage addSubview:number3];
    
    
}

-(void)setDateLabelWithWeek:(NSNumber*)week andMonth:(NSNumber*)month{
    
    dateLabel.text = languagesKorean ? [NSString stringWithFormat:@"%d월 %d주차 무한배틀순위",[month integerValue],[week integerValue]] :
    [NSString stringWithFormat:@"%d th week %@, Battle winner",[week integerValue],[self monthInEnglish:[month integerValue]]];
    
}

-(NSString*)monthInEnglish:(NSInteger)month{

    NSString *string = nil;
    if (month == 1) {
        string = @"Jan";
    }else if (month == 2){
        string = @"Feb";
    }else if (month == 3){
        string = @"Mar";
    }else if(month == 4){
        string = @"Apr";
    }else if (month == 5){
        string = @"May";
    }else if (month == 6){
        string = @"Jun";
    }else if(month == 7){
        string = @"Jul";
    }else if(month == 8){
        string = @"Aug";
    }else if (month == 9){
        string = @"Sep";
    }else if (month == 10){
        string = @"Oct";
    }else if (month == 11){
        string = @"Nov";
    }else if (month == 12){
        string = @"Dec";
    }
    return string;
}

                                                                                               


@end















;